﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LDTB.Service;

namespace LDTB
{
    public partial class CatOptAddFrm : Form
    {
        LDTBDataDataContext ds = DataService.DB;

        public CatOptAddFrm()
        {
            InitializeComponent();
        }

        private void CatOptAddFrm_Load(object sender, EventArgs e)
        {

            var cat = from c in ds.CateObjects
                      select c;

            ddl.DataSource = cat;
            ddl.DisplayMember = "CatName";
            ddl.ValueMember = "CatID";

        }

        private void button1_Click(object sender, EventArgs e)
        {

            string name = textBox1.Text.Trim();
            int id= int.Parse( ddl.SelectedValue.ToString());

            if (name != null)
            {
                var catop = new OptionCate {DegreeName=name,CateDisableID=id };
                ds.OptionCates.InsertOnSubmit(catop);
                ds.SubmitChanges();
                if (catop.ID != 0)
                {
                    MessageBox.Show("thêm thành công");
                    this.textBox1.Text = "";
                }
                else {

                    MessageBox.Show("Thêm không thành công");
                }
            }
            else {

                MessageBox.Show("Nhập tên đanh mục ");
            
            }


        }
    }
}
